package com.yeebo.common;

import com.yeebo.enums.ResultCode;
import com.yeebo.exception.ServiceException;
import com.yeebo.rpc.config.ConfigService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@RestController
@RequestMapping("file")
public class FileController extends BaseController {

    @Resource
    private ConfigService configService;

    /**
     * 文件上传控制层接口
     */
    @RequestMapping("/uploadImageAndGetUrl")
    @ResponseBody
    public Object uploadImageAndGetUrl(@RequestParam("file") MultipartFile file) {
        if (file == null) {
            throw new ServiceException(ResultCode.ERROR);
        }
        return success(configService.uploadImageFileToYunOSS(file));
    }

}
